<template>
  <div class="app-container">
    <component :is="currentRole" />
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import admin from './admin'
import defaultDashboard from './default'

export default {
  name: 'Dashboard',
  components: { admin, defaultDashboard },
  data() {
    return {
      currentRole: 'defaultDashboard'
    }
  },
  computed: {
    ...mapGetters(['roles'])
  },
  created() {
    if (this.roles.indexOf('store') !== -1) {
      this.currentRole = 'store'
    } else {
      for (var i = 0; i < this.roles.length; i++) {
        var role = this.roles[i]
        if (this.hasComponent(role)) {
          this.currentRole = role
          break
        }
      }
    }
  },
  methods: {
    hasComponent(name) {
      return this.$options.components[name]
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container > .el-container {
  padding: 20px 0;
}
</style>
